class Person {
    //声明构造器当中的属性的类型
    name: string;
    age: number;
    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;

    }

    //原型对象上的方法
    jump(a: string): string {
        return a + this.name
    }

    //class类 自身上的方法
    static run(x: number): number {
        return x
    }
}
let tom = new Person("aaa111111111111111", 18);

console.log(tom);

//如果调用原型对象上的方法   使用实例对象可以通过隐式原型链访问到原型对象上的方法
console.log(tom.jump('aaa'));

//class类或者构造函数自身上的方法如何调用   对象自身上的方法  obj.xxx  obj['xxx']
console.log(Person.run(5));

//接口定义类的数据类型时，
//语法： class 类名 implements  定义的接口名{}
interface Anima {
    sound(str: string): string,
    weight(num: number): number
}

class Cat implements Anima {
    sound(a: string): string {
        return a
    }
    weight(num: number): number {
        return num
    }
}
let kitty = new Cat();
console.log(kitty);
console.log(kitty.sound('呜啊'));
console.log(kitty.sound('汪汪的叫')); 



interface Anima1{
    name(str:string):string
}
// 一个类可以使用多个接口进行规定  通过implements
class mon implements Anima,Anima1{
    sound(a: string): string {
        return a
    }
    weight(num: number): number {
        return num
    }
    name(str: string): string {
        return str
    }
}
let moon = new mon();
console.log(moon);
console.log(moon.sound('呜啊11'));
console.log(moon.sound('汪汪的叫22')); 




// 有两个接口单写有点麻烦  通过 继承合并成一个
interface DogInP {
    sound(str: string): string,
}

interface DogInC {
    run(num: number): number
}

interface NewIn extends DogInP, DogInC {

}

class Dog implements NewIn {
    sound(str: string): string {
        return str
    }
    run(num: number): number {
        return num
    }
}
let dahuang = new Dog()
console.log(dahuang.sound('汪汪汪333'));
console.log(dahuang.run(1000));

class Students extends Person {
    sex :"string";
    constructor (name :string,age:number,sex:string){
        super(name,age);
        // this.sex = sex;
    }
    jump(a:string):string{
        return super.jump(a)
    }
}
let sizhe = new Students('sizhe', 15, "男");
console.log(sizhe.jump('2米高'));



// 修饰符 
// public 默认值哪里都有访问
// private 私有的 只有内部可以访问
// protected 受保护的 只有内部和子类可以访问

class Book {
    public name :string;
    private price:string;
    protected pages :number;
    constructor(name:string,price:string,pages:number){
        this.name = name;
        this.price = price;
        this.pages = pages;
    }
   sayBook():string{
    //在class内部访问
       console.log(this.price);
       console.log(this.pages);

       return this.name
       
   }
   
    
}
let hongloumeng = new Book('hongloumeng', '200块', 1500);
console.log(hongloumeng.name);
console.log(hongloumeng);
console.log(hongloumeng.sayBook());

//在class外部访问不到
// console.log(hongloumeng.price);
// console.log(hongloumeng.pages);

class HouBook extends Book {
    constructor (name :string,price:string,pages:number){
        super(name,price,pages);

    }
    testPrice(){
        console.log(this.name);
        console.log(this.pages);
         
        
    }
}

let xiaohongshu = new HouBook("hongshu","500块",1000000000);
console.log(xiaohongshu.testPrice());




















export {
    tom,
}